﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using ERP_RORZE_SYSTEM;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Globalization;
using System.Threading;

namespace ERP_RORZE_DLL.Assembly
{
    public partial class frm_Edit_F4CheckRR713 : Form
    {
        private INISettings mySetting;
        private SqlConnection myConnection;

        private Dictionary<string, string> required_list;

        private DataSet ds;
        private DataViewManager dsView;

        public string serial;

        public frm_Edit_F4CheckRR713()
        {
            InitializeComponent();
            this.mySetting = new INISettings();
            this.myConnection = new SqlConnection(mySetting.SQLConnectionString);

            this.serial = null;

            this.ds = new DataSet("RobotOrderDetail");

            this.required_list = new Dictionary<string, string>() { { "serialNo", "Serial No" }, { "writtenBy", "Written By" },
            { "checkBy", "Check By"}, {"inputDate", "Date"}, {"wiringDiagram", "Wiring Diagram"}, {"A1_RC234", "A1 RC234"}, 
            {"A1_RC234Ver", "A1 RC234 Ver"}, {"A1_RC234No", "A1 RC234 No"}, {"A1_RD026", "A1 RD026"}, {"A1_Run", "A1 Run"},
            {"A1_Stop", "A1 Stop"}, {"A2_RC234", "A2 RC234"}, {"A2_RC234Ver", "A2 RC234 Ver"}, {"A2_RC234No", "A2 RC234 No"}, 
            {"A2_RD026", "A2 RD026"}, {"A2_Run", "A2 Run"}, {"A2_Stop", "A2 Stop"}, {"R_RC234", "R RC234"},
            {"R_RC234Ver", "R RC234 Ver"}, {"R_RC234No", "R RC234 No"}, {"Rot_RD026", "Rot RD026"}, {"Rot_Run", "Rot Run"},
            {"Rot_Stop", "Rot Stop"}, {"Z_RC234", "Z RC234"}, {"Z_RC234Ver", "Z RC234 Ver"}, {"Z_RC234No", "Z RC234 No"},
            {"Z_RD026", "Z RD026"}, {"Z_Run", "Z Run"}, {"Z_Stop", "Z Stop"}, {"RC204", "RC204"}, {"RC204Ver", "RC204 Ver"},
            {"RC204No", "RC204 No"}, {"A1_R022A", "A1-R022A"}, {"A2_R022A", "A2-R022A"}};

            LoadStaffList();
            LoadDefaultData();            
        }

        ////////////////////////////////////////////////////
        /// Load Serial List
        ////////////////////////////////////////////////////
        private void LoadSerialList()
        {
            try
            {
                myConnection.Open();
                SqlCommand cmd_sql = myConnection.CreateCommand();
                cmd_sql.CommandText = "SELECT [SerialNo], [CompID] FROM [231_RobotOrderDetail]"
                    + " WHERE(FinishedDate > DateAdd(dd, 0, DateDiff(dd, 0, GETDATE())) - 500) AND [SerialNo] NOT IN"
                    + " (SELECT [SerialNo] COLLATE Vietnamese_CI_AS FROM [231_UnitRR713] WHERE [SerialNo] <> '" + this.serial + "')";
                SqlDataAdapter da1 = new SqlDataAdapter();
                da1.SelectCommand = cmd_sql;
                da1.TableMappings.Add("Table", "RobotOrderDetail");
                da1.Fill(ds);
                dsView = ds.DefaultViewManager;
                cmd_sql.Dispose();
                myConnection.Close();

                this.serialNo.DataSource = dsView;
                this.serialNo.DisplayMember = "RobotOrderDetail.SerialNo";
                this.serialNo.ValueMember = "RobotOrderDetail.SerialNo";
                this.serialNo.AutoCompleteSource = AutoCompleteSource.ListItems;

                this.partNo.DataBindings.Add("Text", dsView, "RobotOrderDetail.CompID");
            }
            catch (Exception ex)
            {
                if (myConnection.State == ConnectionState.Open)
                {
                    myConnection.Close();
                }
                MessageBox.Show(ex.Message);
            }
        }

        /// <summary>
        /// Load Staff List
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LoadStaffList()
        {
            try
            {
                myConnection.Open();
                SqlCommand sql_cmd = myConnection.CreateCommand();
                sql_cmd.CommandText = "SELECT StaffID, StaffName FROM [222_Staff] WHERE StopDate IS NULL ORDER BY StaffID";
                SqlDataReader dataReader = sql_cmd.ExecuteReader();
                while (dataReader.Read())
                {
                    ComboboxItem item = new ComboboxItem();
                    string[] fullname = dataReader["StaffName"].ToString().Trim().Split(' ');

                    CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
                    TextInfo textInfo = cultureInfo.TextInfo;
                    string txt = textInfo.ToTitleCase(fullname[fullname.Length - 1].ToLower());

                    item.Text = txt + dataReader["StaffID"].ToString().Trim();
                    item.Value = txt + dataReader["StaffID"].ToString().Trim();

                    this.writtenBy.Properties.Items.Add(item);
                    this.checkBy.Properties.Items.Add(item);
                }
                dataReader.Close();
                sql_cmd.Dispose();
                myConnection.Close();
            }
            catch (Exception ex)
            {
                if (myConnection.State == ConnectionState.Open)
                {
                    myConnection.Close();
                }
                MessageBox.Show(ex.Message);
            }
        }

        ////////////////////////////////////////////////////
        /// Load Default Data
        ////////////////////////////////////////////////////
        private void LoadDefaultData()
        {
            try
            {
                myConnection.Open();
                SqlCommand cmd_sql = myConnection.CreateCommand();
                cmd_sql.CommandText = "SELECT DISTINCT [Wiring Daiagram]"
                    + " FROM [231_UnitRR713]";
                SqlDataReader dataReader = cmd_sql.ExecuteReader();
                while (dataReader.Read())
                {
                    ComboboxItem item = new ComboboxItem();
                    item.Value = dataReader["Wiring Daiagram"].ToString().Trim();
                    item.Text = dataReader["Wiring Daiagram"].ToString().Trim();

                    this.wiringDiagram.Properties.Items.Add(item);
                }
                dataReader.Close();
                cmd_sql.Dispose();
                
                cmd_sql = myConnection.CreateCommand();
                cmd_sql.CommandText = "SELECT [SerialNo] FROM [231_F5Detail]"
                    + " WHERE ([FinishDate] > DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())) - 500)";
                dataReader = cmd_sql.ExecuteReader();
                while (dataReader.Read())
                {
                    ComboboxItem item = new ComboboxItem();
                    item.Value = dataReader["SerialNo"].ToString().Trim();
                    item.Text = dataReader["SerialNo"].ToString().Trim();

                    this.A1_RC234.Properties.Items.Add(item);
                    this.A1_RD026.Properties.Items.Add(item);
                    this.A2_RC234.Properties.Items.Add(item);                    
                    this.A2_RD026.Properties.Items.Add(item);
                    this.R_RC234.Properties.Items.Add(item);                    
                    this.Rot_RD026.Properties.Items.Add(item);
                    this.Z_RC234.Properties.Items.Add(item);
                    this.Z_RD026.Properties.Items.Add(item);
                    this.RC204.Properties.Items.Add(item);
                }
                dataReader.Close();
                cmd_sql.Dispose();
                myConnection.Close();
            }
            catch (Exception ex)
            {
                if (myConnection.State == ConnectionState.Open)
                {
                    myConnection.Close();
                }
                MessageBox.Show(ex.Message);
            }
        }

        /// <summary>
        /// Load Data to Edit
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public bool LoadData()
        {
            bool ret = true;
            if (string.IsNullOrEmpty(this.serial))
            {
                ret = false;
            }
            else
            {
                LoadSerialList();
                try
                {
                    myConnection.Open();
                    SqlCommand sql_cmd = myConnection.CreateCommand();
                    sql_cmd.CommandText = "SELECT t1.[SerialNo], t1.[Written], t1.[Date], t1.[Checked], t1.[Wiring Daiagram],"
                        + " t1.[A1 RC234], t1.[A1 RC234 Ver], t1.[A1 RC234 No], t1.[A1 RD026], t1.[A1 run], t1.[A1 stop],"
                        + " t1.[A2 RC234], t1.[A2 RC234 Ver], t1.[A2 RC234 No], t1.[A2 RD026], t1.[A2 run], t1.[A2 stop],"
                        + " t1.[R RC234], t1.[R RC234 Ver], t1.[R RC234 No], t1.[Rot RD026], t1.[Rot run], t1.[Rot stop],"
                        + " t1.[Z RC234], t1.[Z RC234 Ver], t1.[Z RC234 No], t1.[Z RD026], t1.[Z run], t1.[Z stop],"
                        + " t1.[RC204], t1.[RC204 Ver], t1.[RC204 No], t1.[A1-R022A], t1.[A2-R022A], t1.[A1-OH], t1.[A1-OL],"
                        + " t1.[A1-Q], t1.[A1-QA], t1.[A1-OX], t1.[A1-OC], t1.[A1-OS], t1.[A1-0S], t1.[A2-OH], t1.[A2-OL],"
                        + " t1.[A2-Q], t1.[A2-QA], t1.[A2-OX], t1.[A2-OC], t1.[A2-OS], t1.[A2-0S], t1.[R-OH], t1.[R-OL],"
                        + " t1.[R-Q], t1.[R-OX], t1.[R-OC], t1.[R-OS], t1.[R-0S], t1.[Z-OH], t1.[Z-OL], t1.[Z-Q], t1.[Z-OX],"
                        + " t1.[Z-OC], t1.[Z-OS], t1.[Z-0S], t1.[Remark], t2.CompID"
                        + " FROM [231_UnitRR713] AS t1 LEFT JOIN"
                        + " [231_RobotOrderDetail] AS t2 ON t1.[SerialNo] COLLATE Vietnamese_CI_AS=t2.[SerialNo]"
                        + " WHERE t1.[SerialNo]='" + this.serial + "'";
                    SqlDataReader dataReader = sql_cmd.ExecuteReader();
                    if (dataReader.Read())
                    {                        
                        this.serialNo.SelectedIndex = this.serialNo.FindString(serial);                        
                        for (int i = 0; i < this.writtenBy.Properties.Items.Count; i++)
                        {
                            ComboboxItem item = (ComboboxItem)this.writtenBy.Properties.Items[i];
                            if (item.Value.ToString().ToUpper() == dataReader["Written"].ToString().Trim().ToUpper())
                            {
                                this.writtenBy.SelectedIndex = i;
                            }
                        }
                        this.inputDate.EditValue = DateTime.Parse(dataReader["Date"].ToString().Trim());
                        
                        for (int i = 0; i < this.checkBy.Properties.Items.Count; i++)
                        {
                            ComboboxItem item = (ComboboxItem)this.checkBy.Properties.Items[i];
                            if (item.Value.ToString().ToUpper() == dataReader["Checked"].ToString().Trim().ToUpper())
                            {
                                this.checkBy.SelectedIndex = i;
                            }
                        }
                        
                        for (int i = 0; i < this.wiringDiagram.Properties.Items.Count; i++)
                        {
                            ComboboxItem item = (ComboboxItem)this.wiringDiagram.Properties.Items[i];
                            if (item.Value.ToString() == dataReader["Wiring Daiagram"].ToString().Trim())
                            {
                                this.wiringDiagram.SelectedIndex = i;
                            }
                        }

                        for (int i = 0; i < this.A1_RC234.Properties.Items.Count; i++)
                        {
                            ComboboxItem item = (ComboboxItem)this.A1_RC234.Properties.Items[i];
                            if (item.Value.ToString() == dataReader["A1 RC234"].ToString().Trim())
                            {
                                this.A1_RC234.SelectedIndex = i;
                            }
                        }
                        this.A1_RC234Ver.Text = dataReader["A1 RC234 Ver"].ToString().Trim();
                        this.A1_RC234No.Text = dataReader["A1 RC234 No"].ToString().Trim();

                        for (int i = 0; i < this.A1_RD026.Properties.Items.Count; i++)
                        {
                            ComboboxItem item = (ComboboxItem)this.A1_RD026.Properties.Items[i];
                            if (item.Value.ToString() == dataReader["A1 RD026"].ToString().Trim())
                            {
                                this.A1_RD026.SelectedIndex = i;
                            }
                        }
                        this.A1_Run.Text = dataReader["A1 run"].ToString().Trim();
                        this.A1_Stop.Text = dataReader["A1 stop"].ToString().Trim();

                        for (int i = 0; i < this.A2_RC234.Properties.Items.Count; i++)
                        {
                            ComboboxItem item = (ComboboxItem)this.A2_RC234.Properties.Items[i];
                            if (item.Value.ToString() == dataReader["A2 RC234"].ToString().Trim())
                            {
                                this.A2_RC234.SelectedIndex = i;
                            }
                        }
                        this.A2_RC234Ver.Text = dataReader["A2 RC234 Ver"].ToString().Trim();
                        this.A2_RC234No.Text = dataReader["A2 RC234 No"].ToString().Trim();
                        
                        for (int i = 0; i < this.A2_RD026.Properties.Items.Count; i++)
                        {
                            ComboboxItem item = (ComboboxItem)this.A2_RD026.Properties.Items[i];
                            if (item.Value.ToString() == dataReader["A2 RD026"].ToString().Trim())
                            {
                                this.A2_RD026.SelectedIndex = i;
                            }
                        }
                        this.A2_Run.Text = dataReader["A2 run"].ToString().Trim();
                        this.A2_Stop.Text = dataReader["A2 stop"].ToString().Trim();

                        for (int i = 0; i < this.R_RC234.Properties.Items.Count; i++)
                        {
                            ComboboxItem item = (ComboboxItem)this.R_RC234.Properties.Items[i];
                            if (item.Value.ToString() == dataReader["R RC234"].ToString().Trim())
                            {
                                this.R_RC234.SelectedIndex = i;
                            }
                        }
                        this.R_RC234Ver.Text = dataReader["R RC234 Ver"].ToString().Trim();
                        this.R_RC234No.Text = dataReader["R RC234 No"].ToString().Trim();

                        for (int i = 0; i < this.Rot_RD026.Properties.Items.Count; i++)
                        {
                            ComboboxItem item = (ComboboxItem)this.Rot_RD026.Properties.Items[i];
                            if (item.Value.ToString() == dataReader["Rot RD026"].ToString().Trim())
                            {
                                this.Rot_RD026.SelectedIndex = i;
                            }
                        }
                        this.Rot_Run.Text = dataReader["Rot run"].ToString().Trim();
                        this.Rot_Stop.Text = dataReader["Rot stop"].ToString().Trim();

                        for (int i = 0; i < this.Z_RC234.Properties.Items.Count; i++)
                        {
                            ComboboxItem item = (ComboboxItem)this.Z_RC234.Properties.Items[i];
                            if (item.Value.ToString() == dataReader["Z RC234"].ToString().Trim())
                            {
                                this.Z_RC234.SelectedIndex = i;
                            }
                        }
                        this.Z_RC234Ver.Text = dataReader["Z RC234 Ver"].ToString().Trim();
                        this.Z_RC234No.Text = dataReader["Z RC234 No"].ToString().Trim();

                        for (int i = 0; i < this.Z_RD026.Properties.Items.Count; i++)
                        {
                            ComboboxItem item = (ComboboxItem)this.Z_RD026.Properties.Items[i];
                            if (item.Value.ToString() == dataReader["Z RD026"].ToString().Trim())
                            {
                                this.Z_RD026.SelectedIndex = i;
                            }
                        }
                        this.Z_Run.Text = dataReader["Z run"].ToString().Trim();
                        this.Z_Stop.Text = dataReader["Z stop"].ToString().Trim();

                        for (int i = 0; i < this.RC204.Properties.Items.Count; i++)
                        {
                            ComboboxItem item = (ComboboxItem)this.RC204.Properties.Items[i];
                            if (item.Value.ToString() == dataReader["RC204"].ToString().Trim())
                            {
                                this.RC204.SelectedIndex = i;
                            }
                        }
                        this.RC204Ver.Text = dataReader["RC204 Ver"].ToString().Trim();
                        this.RC204No.Text = dataReader["RC204 No"].ToString().Trim();

                        this.A1_R022A.Text = dataReader["A1-R022A"].ToString().Trim();
                        this.A2_R022A.Text = dataReader["A2-R022A"].ToString().Trim();

                        this.A1_OH.Text = dataReader["A1-OH"].ToString().Trim();
                        this.A1_OL.Text = dataReader["A1-OL"].ToString().Trim();
                        this.A1_Q.Text = dataReader["A1-Q"].ToString().Trim();
                        this.A1_OX.Text = dataReader["A1-OX"].ToString().Trim();
                        this.A1_OC.Text = dataReader["A1-OC"].ToString().Trim();
                        this.A1_OS.Text = dataReader["A1-OS"].ToString().Trim();
                        this.A1_0S.Text = dataReader["A1-0S"].ToString().Trim();

                        this.A2_OH.Text = dataReader["A2-OH"].ToString().Trim();
                        this.A2_OL.Text = dataReader["A2-OL"].ToString().Trim();
                        this.A2_Q.Text = dataReader["A2-Q"].ToString().Trim();
                        this.A2_OX.Text = dataReader["A2-OX"].ToString().Trim();
                        this.A2_OC.Text = dataReader["A2-OC"].ToString().Trim();
                        this.A2_OS.Text = dataReader["A2-OS"].ToString().Trim();
                        this.A2_0S.Text = dataReader["A2-0S"].ToString().Trim();

                        this.R_OH.Text = dataReader["R-OH"].ToString().Trim();
                        this.R_OL.Text = dataReader["R-OL"].ToString().Trim();
                        this.R_Q.Text = dataReader["R-Q"].ToString().Trim();
                        this.R_OX.Text = dataReader["R-OX"].ToString().Trim();
                        this.R_OC.Text = dataReader["R-OC"].ToString().Trim();
                        this.R_OS.Text = dataReader["R-OS"].ToString().Trim();
                        this.R_0S.Text = dataReader["R-0S"].ToString().Trim();

                        this.Z_OH.Text = dataReader["Z-OH"].ToString().Trim();
                        this.Z_OL.Text = dataReader["Z-OL"].ToString().Trim();
                        this.Z_Q.Text = dataReader["Z-Q"].ToString().Trim();
                        this.Z_OX.Text = dataReader["Z-OX"].ToString().Trim();
                        this.Z_OC.Text = dataReader["Z-OC"].ToString().Trim();
                        this.Z_OS.Text = dataReader["Z-OS"].ToString().Trim();
                        this.Z_0S.Text = dataReader["Z-0S"].ToString().Trim();

                        this.Remark.Text = dataReader["Remark"].ToString().Trim();
                    }
                    sql_cmd.Dispose();
                    myConnection.Close();
                }
                catch
                {
                    if (myConnection.State == ConnectionState.Open)
                    {
                        myConnection.Close();
                    }
                    ret = false;
                }
            }
            return ret;
        }
        
        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
        
        ///////////////////////////
        /// When Click Add Button
        ///////////////////////////        
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            string error = null;

            foreach (Control c in this.Controls)
            {
                if (c is System.Windows.Forms.ComboBox)
                {
                    if (((System.Windows.Forms.ComboBox)c).SelectedIndex < 0)
                    {
                        if (required_list.ContainsKey(((System.Windows.Forms.ComboBox)c).Name))
                        {
                            error = "Please select " + required_list[((System.Windows.Forms.ComboBox)c).Name];
                        }
                    }
                }

                if (c is DevExpress.XtraEditors.ComboBoxEdit)
                {
                    if (((DevExpress.XtraEditors.ComboBoxEdit)c).SelectedIndex < 0)
                    {
                        if (required_list.ContainsKey(((DevExpress.XtraEditors.ComboBoxEdit)c).Name))
                        {
                            error = "Please select " + required_list[((DevExpress.XtraEditors.ComboBoxEdit)c).Name];
                        }
                    }
                }

                if (c is DevExpress.XtraEditors.TextEdit)
                {
                    if (string.IsNullOrEmpty(((DevExpress.XtraEditors.TextEdit)c).Text.Trim()))
                    {
                        if (required_list.ContainsKey(((DevExpress.XtraEditors.TextEdit)c).Name))
                        {
                            error = "Please enter " + required_list[((DevExpress.XtraEditors.TextEdit)c).Name];
                        }
                    }
                }

                if (c is System.Windows.Forms.TextBox)
                {
                    if (string.IsNullOrEmpty(((System.Windows.Forms.TextBox)c).Text.Trim()))
                    {
                        if (required_list.ContainsKey(((System.Windows.Forms.TextBox)c).Name))
                        {
                            error = "Please enter " + required_list[((System.Windows.Forms.TextBox)c).Name];
                        }
                    }
                }                
            }            

            if (string.IsNullOrEmpty(error))
            {
                DateTime date = DateTime.Parse(this.inputDate.EditValue.ToString());
                try
                {
                    myConnection.Open();
                    SqlCommand sql_cmd = myConnection.CreateCommand();
                    sql_cmd.CommandText = "UPDATE [231_UnitRR713] SET"
                        + " [A1 RC234]='" + this.A1_RC234.Text.Trim() + "',"
                        + " [A1 RC234 Ver]='" + this.A1_RC234Ver.Text.Trim() + "',"
                        + " [A1 RC234 No]='" + this.A1_RC234No.Text.Trim() + "',"                        
                        + " [A1 RD026]='" + this.A1_RD026.Text.Trim() + "', [A1 run]='" + this.A1_Run.Text.Trim() + "',"
                        + " [A1 stop]='" + this.A1_Stop.Text.Trim() + "',"

                        + " [A2 RC234]='" + this.A2_RC234.Text.Trim() + "',"
                        + " [A2 RC234 Ver]='" + this.A2_RC234Ver.Text.Trim() + "',"
                        + " [A2 RC234 No]='" + this.A2_RC234No.Text.Trim() + "',"
                        + " [A2 RD026]='" + this.A2_RD026.Text.Trim() + "', [A2 run]='" + this.A2_Run.Text.Trim() + "',"
                        + " [A2 stop]='" + this.A2_Stop.Text.Trim() + "',"

                        + " [R RC234]='" + this.R_RC234.Text.Trim() + "',"
                        + " [R RC234 Ver]='" + this.R_RC234Ver.Text.Trim() + "',"
                        + " [R RC234 No]='" + this.R_RC234No.Text.Trim() + "',"
                        + " [Rot RD026]='" + this.Rot_RD026.Text.Trim() + "', [Rot run]='" + this.Rot_Run.Text.Trim() + "',"
                        + " [Rot stop]='" + this.Rot_Stop.Text.Trim() + "',"

                        + " [Z RC234]='" + this.Z_RC234.Text.Trim() + "',"
                        + " [Z RC234 Ver]='" + this.Z_RC234Ver.Text.Trim() + "',"
                        + " [Z RC234 No]='" + this.Z_RC234No.Text.Trim() + "',"
                        + " [Z RD026]='" + this.Z_RD026.Text.Trim() + "',"
                        + " [Z run]='" + this.Z_Run.Text.Trim() + "', [Z stop]='" + this.Z_Stop.Text.Trim() + "',"

                        + " [RC204]='" + this.RC204.Text.Trim() + "',"
                        + " [RC204 Ver]='" + this.RC204Ver.Text.Trim() + "',"
                        + " [RC204 No]='" + this.RC204No.Text.Trim() + "',"

                        + " [A1-R022A]='" + this.A1_R022A.Text.Trim() + "',"
                        + " [A2-R022A]='" + this.A2_R022A.Text.Trim() + "',"

                        + " [A1-OH]=NULLIF('" + this.A1_OH.Text.Trim() + "', ''), [A1-OL]=NULLIF('" + this.A1_OL.Text.Trim() + "', ''),"
                        + " [A1-Q]=NULLIF('" + this.A1_Q.Text.Trim() + "', ''), [A1-OX]=NULLIF('" + this.A1_OX.Text.Trim() + "', ''),"
                        + " [A1-OC]=NULLIF('" + this.A1_OC.Text.Trim() + "', ''), [A1-OS]=NULLIF('" + this.A1_OS.Text.Trim() + "', ''),"
                        + " [A1-0S]=NULLIF('" + this.A1_0S.Text.Trim() + "', ''), [A2-OH]=NULLIF('" + this.A2_OH.Text.Trim() + "', ''),"
                        + " [A2-OL]=NULLIF('" + this.A2_OL.Text.Trim() + "', ''), [A2-Q]=NULLIF('" + this.A2_Q.Text.Trim() + "', ''),"
                        + " [A2-OX]=NULLIF('" + this.A2_OX.Text.Trim() + "', ''), [A2-OC]=NULLIF('" + this.A2_OC.Text.Trim() + "', ''),"
                        + " [A2-OS]=NULLIF('" + this.A2_OS.Text.Trim() + "', ''), [A2-0S]=NULLIF('" + this.A2_0S.Text.Trim() + "', ''),"
                        + " [R-OH]=NULLIF('" + this.R_OH.Text.Trim() + "', ''), [R-OL]=NULLIF('" + this.R_OL.Text.Trim() + "', ''),"
                        + " [R-Q]=NULLIF('" + this.R_Q.Text.Trim() + "', ''), [R-OX]=NULLIF('" + this.R_OX.Text.Trim() + "', ''),"
                        + " [R-OC]=NULLIF('" + this.R_OC.Text.Trim() + "', ''), [R-OS]=NULLIF('" + this.R_OS.Text.Trim() + "', ''),"
                        + " [R-0S]=NULLIF('" + this.R_0S.Text.Trim() + "', ''), [Z-OH]=NULLIF('" + this.Z_OH.Text.Trim() + "', ''),"
                        + " [Z-OL]=NULLIF('" + this.Z_OL.Text.Trim() + "', ''), [Z-Q]=NULLIF('" + this.Z_Q.Text.Trim() + "', ''),"
                        + " [Z-OX]=NULLIF('" + this.Z_OX.Text.Trim() + "', ''), [Z-OC]=NULLIF('" + this.Z_OC.Text.Trim() + "', ''),"
                        + " [Z-OS]=NULLIF('" + this.Z_OS.Text.Trim() + "', ''), [Z-0S]=NULLIF('" + this.Z_0S.Text.Trim() + "', ''),"
                        + " [Remark]='" + this.Remark.Text.Trim() + "'"
                        + " WHERE [SerialNo]='" + this.serialNo.Text.Trim() + "'";
                    sql_cmd.ExecuteNonQuery();
                    sql_cmd.Dispose();
                    myConnection.Close();
                    MessageBox.Show("Database updated successfully!");
                    this.Dispose();
                }
                catch (Exception ex)
                {
                    if (myConnection.State == ConnectionState.Open)
                    {
                        myConnection.Close();
                    }
                    MessageBox.Show(ex.Message);
                }                
            }
            else
            {
                MessageBox.Show(error);
            }
        }      
    }
}
